package com.dragon.logical.service.avttendance.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.common.model.ResultCode;
import com.dragon.common.model.exception.CustomException;
import com.dragon.logical.service.avttendance.IArrangePointsService;
import com.dragon.repository.entity.ArrangePoints;
import com.dragon.repository.mapper.ArrangePointsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 考勤点 服务实现类
 * </p>
 *
 * @author sy
 * @since 2023-07-31
 */
@Service
public class ArrangePointsServiceImpl extends ServiceImpl<ArrangePointsMapper, ArrangePoints> implements IArrangePointsService {

    @Autowired
    ArrangePointsMapper pointsMapper;

    @Override
    public List<ArrangePoints> pointsList(String search) {
        QueryWrapper<ArrangePoints> wrapper = new QueryWrapper<>();
        wrapper.lambda().like(StrUtil.isNotBlank(search),ArrangePoints::getPointsName,search);
        return pointsMapper.selectList(wrapper);
    }

    @Override
    public void pointsAdd(ArrangePoints points) {
        points.setCreateTime(DateUtil.date());
        pointsMapper.insert(points);
    }

    @Override
    public void pointsDelete(Integer id) {
        pointsMapper.deleteById(id);
    }

    @Override
    public void pointsUpdate(ArrangePoints points) {
        if (pointsMapper.selectById(points.getId()) == null){
            throw new CustomException(ResultCode.DATA_NOT_FOUND);
        }
        pointsMapper.updateById(points);
    }
}
